package repository.impl;

import Util.JDBCtool;
import entity.Admin;
import entity.Reader;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminRepositoryImpl {

    public Admin login(String username, String password) throws SQLException {
        Connection connection = JDBCtool.getConnection();
        String sql = "select * from admin where username =? and password =?";
        ResultSet resultSet = null;
        Admin admin = null;
        PreparedStatement statement = null;
        statement = connection.prepareStatement(sql);
        statement.setString(1, username);
        statement.setString(2, password);
        resultSet = statement.executeQuery();
        if (resultSet.next()) {
            admin = new Admin(resultSet.getInt(1), resultSet.getString(2), resultSet.getString(3));
        }
        JDBCtool.release(connection, statement, resultSet);
        return admin;
    }
}
